package com.test.hanlp.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Package: com.test.api.knife4j.config
 * @ClassName SwaggerConfiguration
 * @Description:
 * @Author: Dong
 * @Date 2020/4/28 13:05
 * @Version 1.0
 **/
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfiguration {


  @Bean(value = "defaultApi2")
  public Docket defaultApi2() {
    final ApiInfo apiInfo = getApiInfo();
    Docket docket=new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo)
        //分组名称
        .groupName("2.X版本")
        .select()
        //这里指定Controller扫描包路径
        .apis(RequestHandlerSelectors.basePackage("com.test.hanlp"))
        .paths(PathSelectors.any())
        .build();
    return docket;
  }

  /*/**
   * 方法名: getApiInfo <br>
   * 方法参数: [] <br>
   * 方法返回值: springfox.documentation.service.ApiInfo <br>
   * 方法异常:  <br>
   * 方法描述：用于获取 swagger 首页说明设置<br>
   * 作者： Dong<br>
   * 创建日期： 2019/3/8 15:30 <br>
   * 版本： V1.0<br>
   */
  private ApiInfo getApiInfo() {
    //主要用于swagger-ui 主页面上显示
    return new ApiInfoBuilder()
        .title("Rest Api")
        .description("词根接口说明")
        .termsOfServiceUrl("http://www.hexinfo.com")
        .contact(new Contact("test","","xiaji@163.com"))
        .version("1.0.0")
        .build();
  }

}
